function getCombineInfo(tableData) {
  this.spanArr = this.getSpanPosition(tableData, ['objectCode'])
}
function getSpanPosition(list, keys) {
  const newArr = []
  const keyArr = []
  list &&
    list.length &&
    list.forEach((item, i) => {
      const values = keys.map(key => item[key])
      const unique = values.join('')
      if (keyArr.indexOf(unique) === -1) {
        newArr.push([])
        newArr[newArr.length - 1].push(i)
        keyArr.push(unique)
      } else {
        newArr[keyArr.indexOf(unique)].push(i)
      }
    })
  return newArr
}
// 合并单元格
function arraySpanMethod({ row, column, rowIndex, columnIndex }) {
  // 根据对象名称objectCode字段进行合并
  if ([0, 1, 2].includes(columnIndex)) {
    const arr = this.spanArr
    for (let i = 0; i < arr.length; i++) {
      if (rowIndex === arr[i][0]) {
        return {
          rowspan: arr[i].length,
          colspan: 1
        }
      }
    }
    return {
      rowspan: 0,
      colspan: 0
    }
  }
}

/**
 * 获取合并后的序号，待完善，需要支持传页码，要根据页码计算rowindex
 * @param {*} rowIndex 
 * @param {*} spanArr 
 * @returns 
 */
export const getOrderByRowIndex = (rowIndex, spanArr) => {
  if (!spanArr.length) return rowIndex
  // 遍历spanArr数组，找到包含当前行索引的数组
  for (let i = 0; i < spanArr.length; i++) {
    if (spanArr[i].includes(rowIndex)) {
      // 如果是合并行的第一行，返回序号
      if (rowIndex === spanArr[i][0]) {
        return i + 1
      }
      // 如果是被合并的行，返回空字符串
      return rowIndex
    }
  }
  return rowIndex
}